package com.df.base.other;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

public class FileUtils {
    public static List<String> findFiles(String path, Function<String,Boolean> filter){
        Path pathUri = Paths.get(path).toAbsolutePath().normalize();
        List<String> result = new ArrayList<>();
        try {
            Files.walkFileTree(pathUri, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
                    if(filter.apply(file.getFileName().toString())){
                        result.add(file.toAbsolutePath().toString());
                    }
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
}
